﻿myApp.controller("UserCenterCtrl", ['$scope', '$http', '$routeParams', '$restUrls', '$post', '$rootScope', function ($scope, $http, $routeParams, $restUrls, $post, $rootScope) {
    $scope.UserProfile = {};
    $scope.GetCustomerInfo = function (order_id) {
        $http({ method: "GET", url: $restUrls["getCustomerInfo"], params: {} }).success(function (result) {
            if (result.success == 1) {
                $scope.UserProfile = result.data;
            }
        }).error(function (data, status, headers, config) {
            $.scojs_message('服务器忙,请稍候重试', $.scojs_message.TYPE_ERROR);
        });
    }
    $scope.GetCustomerInfo();
    $scope.SetBackGroundImage = function (banner_id) {
        $http({ method: "GET", url: $restUrls["getBannerImagesById"], params: {banner_id:banner_id} }).success(function (result) {
            if (result.success == 1) {
                if (result.data.length > 0) {
                    $('.userinfo').css('background-image', 'url(' + result.data[0].image + ')');
                }
            }
        }).error(function (data, status, headers, config) {
            $.scojs_message('服务器忙,请稍候重试', $.scojs_message.TYPE_ERROR);
        });
    }
    $scope.SetBackGroundImage(9);
    $scope.GetUserDefine1= function () {
        $http({ method: "GET", url: $restUrls["getUserDefine"], params: {user_define_id:1} }).success(function (result) {
            if(result.success==1){
                $scope.UserDefine1 = result.data;
            }
        }).error(function (data, status, headers, config) {

        });

    }
    $scope.GetUserDefine2= function () {
        $http({ method: "GET", url: $restUrls["getUserDefine"], params: {user_define_id:2} }).success(function (result) {
            if(result.success==1){
                $scope.UserDefine2 = result.data;
            }
        }).error(function (data, status, headers, config) {

        });
    }
    $scope.GetUserDefine3= function () {
        $http({ method: "GET", url: $restUrls["getUserDefine"], params: {user_define_id:3} }).success(function (result) {
            if(result.success==1){
                $scope.UserDefine3 = result.data;
            }
        }).error(function (data, status, headers, config) {

        });
    }
    $scope.GetUserDefine1();
    $scope.GetUserDefine2();
    $scope.GetUserDefine3();

    $scope.unReadCount = 0;
        $http({ method: "GET", url: $restUrls["getUnreadCount"], params: {} }).success(function (result) {
        if (result.success == 1) {
            if(parseInt(result.data) >= 10)
                $scope.unReadCount = "10+";
            else
                $scope.unReadCount = result.data;
        }
    }).error(function (data, status, headers, config) {
        $.scojs_message('服务器忙,请稍候重试', $.scojs_message.TYPE_ERROR);
    });

    $scope.msgUnReadCount = 0;
    // $http({ method: "GET", url: $restUrls["getFeedbackUnreadCount"], params: {} }).success(function (result) {
    //     if (result.success == 1) {
    //         $scope.msgUnReadCount = result.data;
    //     }
    // }).error(function (data, status, headers, config) {
    //     $.scojs_message('服务器忙,请稍候重试', $.scojs_message.TYPE_ERROR);
    // });

    $http({ method: "GET", url: $restUrls["getTop4Posts"], params: {} }).success(function (result) {
        if (result.success == 1) {
            $scope.posts = result.data;

            setTimeout(function () {
                var swiper4 = new Swiper('.swiper4', {
                    autoplay : 3000,
                    loop:true
                });
            },1000)
        }


    }).error(function (data, status, headers, config) {
        $.scojs_message('服务器忙,请稍候重试', $.scojs_message.TYPE_ERROR);
    });

}]);